package com.fate.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fate.domain.IndexImg;
import com.fate.vo.IndexImgVo;
import com.fate.service.IndexImgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/indexImg")
@Api(tags = "轮播图管理接口")
public class IndexImgController {

    @Autowired
    private IndexImgService indexImgService;

    /**
     * 分页查询轮播图
     * @param page
     * @param indexImg
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询轮播图")
    @PreAuthorize("hasAuth")
    public ResponseEntity<Page<IndexImg>> findIndexImgPage(Page<IndexImg>page,IndexImg indexImg){
       Page<IndexImg> indexImgPage =  indexImgService.findIndexImgPage(page,indexImg);
       return ResponseEntity.ok(indexImgPage);
    }

    /**
     * 根据id回显轮播图
     */
    @GetMapping("info/{id}")
    @ApiOperation("根据id回显轮播图")
    @PreAuthorize("hasAuthority('admin:indexImg:info')")
    public ResponseEntity<IndexImg> findIndexImgById(@PathVariable("id")Long id){
      IndexImg indexImg = indexImgService.findIndexImgById(id);
      return ResponseEntity.ok(indexImg);
    }

    //-------------前台接口

    /**
     * 微信小程序的业务接口特别注意
     * 因为微信小程序的性能很差
     * 我们每次在做数据传输的时候 一定要注意数据包的大小
     * 前台需要哪个字段我就只给对应的字段即可
     */
    @GetMapping("indexImgs")
    @ApiOperation("加载首页轮播图")
    public ResponseEntity<List<IndexImgVo>> loadFrontIndexImg(){
        List<IndexImgVo> indexImgVos = indexImgService.loadFrontIndexImg();
        return ResponseEntity.ok(indexImgVos);
    }



    //------------远程调用接口




















}
